//app.js
//var Cookie = require("./utils/cookie.js");
//var api = require("./utils/api.js")();
// 引入SDK核心类
var QQMapWX = require('./utils/qqmap/qqmap-wx-jssdk.js');
var systemInfo = {}
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs),
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
  },
  globalData: {
    userInfo: null,
    globalReqUrl: 'https://mini.yingyudsp.com',
    //globalReqUrl: 'https://nanmatou.club/zhiyin',
    //globalReqUrl: 'http://192.168.1.114:7070',
    //globalResourceUrl: 'https://nanmatou.club/files/zhiyin',
    g_isPlayingMusic: false,
    g_currentMusicPostId: null,
    gwapi: "https://www.zhaotool.com",
    //兼容Object.assign
    // if (typeof Object.assign != 'function') {
    //   (function () {
    //     Object.assign = function (target) {
    //       'use strict';
    //       if (target === undefined || target === null) {
    //         throw new TypeError('Cannot convert undefined or null to object');
    //       }

    //       var output = Object(target);
    //       for (var index = 1; index < arguments.length; index++) {
    //         var source = arguments[index];
    //         if (source !== undefined && source !== null) {
    //           for (var nextKey in source) {
    //             if (source.hasOwnProperty(nextKey)) {
    //               output[nextKey] = source[nextKey];
    //             }
    //           }
    //         }
    //       }
    //       return output;
    //     };
    //   })();
    // }
    // __wxConfig.debug && console.info("Object.assign ", typeof Object.assign, typeof Object.defineProperty);
  },
  tradeCurrency: {
    name: "美元",
    description: "USD",
    comments: "U.S.Dollar"
  },
  debitCurrency: {
    name: "人民币",
    description: "CNY",
    comments: "Yuan Renminbi"
  },
  getServerTime: function () {
    return this.globalData.now || new Date()
  },
  getUserInfo: function (cb) {
    __wxConfig.debug && console.log("getUserInfo cb", cb)
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
  globalData: {
    userInfo: null,
    globalReqUrl: 'https://mini.yingyudsp.com',
    //globalReqUrl: 'https://nanmatou.club/zhiyin',
    //globalReqUrl: 'http://192.168.1.114:7070',
    //globalResourceUrl: 'https://nanmatou.club/files/zhiyin',
    g_isPlayingMusic: false,
    g_currentMusicPostId: null,
    gwapi: "https://www.zhaotool.com",
    version: "10.12(10)",
    indate: '',
    outdate: '',
    deepNightFlag: "",
    today: "",
    tomorrow: "",
    yesterday: ""
  },
  getQQMap: function () {
    // 实例划API核心类
    var qqMap = new QQMapWX({
      key: 'KHRBZ-O4PC2-JKPUF-CN6JB-GKL3O-J6FHO' // 必填
    });
    return qqMap;
  }
})
